<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Vue监测数据改变的原理</title>
  <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>


<!-- 准备好一个容器-->
<div id="root">
  <h2>学校名称:{{name}}</h2>
  <h2>学校地址:{{address}}</h2>
  <hr/>
  <button @click="addsex">添加一个性别属性，为男</button>
  <h2>姓名：{{student.name}}</h2>
  <h2 v-if="student.sex">性别：{{student.sex}}</h2>
  <h2>年龄：真实{{student.age.rAge}},对外{{student.age.sAge}}</h2>
  <h2>爱好：</h2>
  <ul>
    <li v-for="(f,index) in student.hobby" :key="index">{{f}}</li>
  </ul>
  <h2>朋友们</h2>
  <ul>
    <li v-for="(f,index) in student.friends" :key="index">
      {{f.name}}--{{f.age}}
    </li>
  </ul>


</div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false

  const vm = new Vue({
    el: '#root',
    data: {
      name: '尚硅谷',
      address: '北京',
      student: {
        name: 'tom',
        age: {
          rAge: 40,
          sAge: 29
        },
        friends: [{
          name: 'jerry',
          age: 35
        }, {
          name: 'tony',
          age: 36
        }],
        hobby:[
            '抽烟','喝酒','烫头'
        ]

      }
    },
    watch: {},
    computed: {},
    methods: {
      addsex(){
        this.$set(this.student,'sex','男')
      }
    },
  })
</script>
</html>